/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

/**
 * <p>Project: jdbc - Demo
 * <p>Powered by jiangbo On 2023-02-14
 * 16:11:08
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Demo {
    public static void main(String[] args) throws Exception {
        //通过Properties集合加载配置文件
        Properties prop=new Properties();
        prop.load(Demo.class.getClassLoader().getResourceAsStream("druid.properties"));
//通过Druid连接池工厂类 获取数据库连接池对象
                DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
//获取连接
        Connection conn = dataSource.getConnection();
//构建sql语句
        String sql="select * from student";
        PreparedStatement pst = conn.prepareStatement(sql);
        ResultSet rs = pst.executeQuery();
        while(rs.next()) {
            System.out.println(rs.getInt("sid") + "\t" + rs.getString("name") + "\t"
                    + rs.getInt("age") + "\t" + rs.getDate("birthday"));
        }
//释放资源
        conn.close();
        pst.close();
        rs.close();
    }

    }



